package com.vip.service.admin.impl;

import com.vip.dao.admin.dao.SysRoleDao;
import com.vip.dao.admin.domain.SysRole;
import com.vip.service.admin.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired
    SysRoleDao sysRoleDao;


    @Override
    public SysRole findRoleByRole(String role) {
        return sysRoleDao.findSysRoleByRole(role);
    }

    @Override
    public void deleteRoleById(Long id) {
        SysRole sysRole = sysRoleDao.findSysRoleByRoleId(id);
        sysRole.setAvailable(false);
        sysRoleDao.save(sysRole);
    }

    @Override
    public SysRole findSysRoleById(Long id) {
        return sysRoleDao.findSysRoleByRoleId(id);
    }

    @Override
    public List<SysRole> findAllSysRole() {
        return sysRoleDao.findAllByAvailable(true);
    }

    @Override
    public Page<SysRole> findAllSysRole(int page, int size) {
        Pageable pageable = PageRequest.of(page,size);
        Page<SysRole> sysRolePage = sysRoleDao.findAll(pageable);
        return sysRolePage;
    }
}
